package com.ttbj.controller.carriageRule;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ttbj.api.carriageRule.CarriageRuleService;
import com.ttbj.api.dto.carriageRule.CarriageRuleDto;
import com.ttbj.api.exception.BusinessException;
import com.ttbj.constant.annotation.SystemControllerLog;
import com.ttbj.util.ViewDataUtil;

@Controller
public class CarriageRuleController {
	
	@Autowired
	private CarriageRuleService carriageRuleService;
	
	
	/**
	 * 短运计价页面
	 * @return
	 */
	@RequestMapping(value="/carriage/carriage_rule.htm")
	public String carriage_rule() {
		return "carriage/carriage_rule";
	} 
	
	/**
	 * 更改短运计价页面
	 * @return
	 */
	@RequestMapping(value="/carriage/edit_carriage.htm")
	public String edit_carriage() {
		return "carriage/edit_carriage";
	}
	
	/**
	 * 获取短运计价信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/carriage/getCarriageInfo.htm", method=RequestMethod.GET, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getCarriageInfo(HttpServletRequest request, HttpServletResponse response) {
		try {
			CarriageRuleDto carriageRuleDto = this.carriageRuleService.findCarriageInfo();
			return ViewDataUtil.buildSuccessJson("短运计价明细", carriageRuleDto);
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	/**
	 * 更新短运计价信息
	 * @param carriageRuleDto 短运计价信息
	 * @return
	 */
	@RequestMapping(value="/carriage/modifyCarriageInfo.htm", method=RequestMethod.POST, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	@SystemControllerLog(description="更改短运计价信息配置")
	public String modifyCarriageInfo(CarriageRuleDto carriageRuleDto) {
		try {
			this.carriageRuleService.editCarriageInfo(carriageRuleDto);
			return ViewDataUtil.buildSuccessJson("更改成功");
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
}
